package cn.mcch.investigator.presenter.impl;

import android.content.Context;
import android.content.Intent;
import android.support.v4.app.FragmentManager;
import android.support.v4.view.ViewPager;
import android.support.v4.view.ViewPager.OnPageChangeListener;

import cn.mcch.investigator.R;
import cn.mcch.investigator.activity.LoginActivity;
import cn.mcch.investigator.adapter.viewpageradapter.MainViewPagerAdapter;
import cn.mcch.investigator.dialog.BaseDialog;
import cn.mcch.investigator.fragment.FragmentFactory;
import cn.mcch.investigator.model.impl.MainModelImpl;
import cn.mcch.investigator.observer.InvestigatorObserverable;
import cn.mcch.investigator.presenter.BasePresenter;
import cn.mcch.investigator.presenter.IMainPresenter;
import cn.mcch.investigator.viewdelegate.impl.MainViewDelegateImpl;

/**
 * Created by Administrator on 2016/12/16.
 */
public class MainPresenterImpl extends BasePresenter<MainViewDelegateImpl, MainModelImpl> implements IMainPresenter {
    @Override
    public Class<MainViewDelegateImpl> getViewDelegateClass() {
        return MainViewDelegateImpl.class;
    }

    @Override
    public Class<MainModelImpl> getModelClass() {
        return MainModelImpl.class;
    }

    @Override
    public void toogle() {
        mViewDelegate.toogle();
    }

    @Override
    public void setUsername(String username) {
        mViewDelegate.setText(R.id.tv_username, username);
    }

    /**
     * 修改titlebar的title
     *
     * @param title
     */
    @Override
    public void setTitleBarText(String title) {
        mViewDelegate.setTitleBarText(title);
    }

    /**
     * 设置viewpager适配器
     *
     * @param fm
     */
    @Override
    public void setViewPagerAdapter(FragmentManager fm) {
        mViewDelegate.setViewPagerAdapter(R.id.vp_content, new MainViewPagerAdapter(fm));
        mViewDelegate.setOffscreenPageLimit(4);
    }

    @Override
    public void exit(BaseDialog dialog, Context context) {
        dialog.dismiss();
        dialog = null;
        FragmentFactory.clear();
        InvestigatorObserverable.clearAllObservers();
        context.startActivity(new Intent(context, LoginActivity.class));
    }

    @Override
    public boolean isDrawerpen() {
        return mViewDelegate.isDrawerOpen();
    }

    @Override
    public void setCurrentItem(int position) {
        mViewDelegate.setCurrentItem(position);
    }

}
